package com.kuang.user.controller;

import com.kuang.bascic.Myexception.BusinessException;
import com.kuang.bascic.utils.AjaxResult;
import com.kuang.user.domian.dto.UserDto;
import com.kuang.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class ReginsController {
    @Autowired
    private UserService userService;
    /**
     *     CodeType: "REGINSTER"
     *     code: "24234"
     *     passwoed: ""
     *     password: "24234"
     *     passwordRepeat: "2423424"
     *     phone: "32424324"
     *     email:""
     *
     *
     */
    @PostMapping("/reg")
    public AjaxResult reg(@RequestBody UserDto userDto){
        System.out.println(userDto.getCodetype());
        try {
            userService.regins(userDto);
            return AjaxResult.me();
        } catch (BusinessException e) {
           return AjaxResult.me().setMessage(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException(e);
        }


    }

}
